This notebook can be used to generate basic scatter plots of all the Pareto-optimal fronts with suitable colorings and point-sizes. This notebook tests the plot() fucntion from the vis.plotting.scatter module. All the Pareto-optimal data point files hard-coded in the dictionary pfs. Currently this notebook provides these Pareto-optimal fronts.
%reload_ext autoreload
%autoreload 2
import sys
import os
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
plt.rcParams.update({'figure.max_open_warning': 0})
sys.path.append('../')
from vis.plotting.utils import resize_by_tradeoff, color_by_dist, color_by_cv, enhance_color
def load_props(path):
r"""
Load CV, Mu, Ik and S from path.
"""
CV = None
cvpathf = os.path.join(path, "datacv.csv")
if os.path.exists(cvpathf):
CV = np.loadtxt(cvpathf)
# load the Mu values
Mu = None
mupathf = os.path.join(path, "mu.csv")
if os.path.exists(mupathf):
Mu = np.loadtxt(mupathf)
# load the knee indices
Ik = None
kpathf = os.path.join(path, "muid.csv")
if os.path.exists(kpathf):
Ik = np.loadtxt(kpathf, dtype = int)
return CV, Mu, Ik
def decide_size_color(CV, Mu, Ik):
r"""
Decide point-size and color from `CV`, `Mu` and `Ik`
"""
# decide point-size
S = 1
if Mu is not None and Ik is not None:
S = resize_by_tradeoff(Mu, k=Ik)
# decide colors
# C = default_color(F.shape[0], alpha=0.5)
M = np.mean(F, axis=0)
C = color_by_dist(F, M)
# if CV is available, use CV to color
if CV is not None:
C = color_by_cv(CV)
# enhance knee points
if Ik is not None:
C = enhance_color(C, Ik)
return S, C
%matplotlib inline
sys.path.append('../')
from vis.plotting import scatter
from vis.plotting.scatter import camera_angles
pfs = {'dtlz2': ['3d', '4d', '8d'], \
'dtlz2-nbi': ['3d', '4d', '8d'], \
'debmdk': ['3d', '4d', '8d'], \
'debmdk-nbi': ['3d', '4d', '8d'], \
'debmdk-all': ['3d', '4d', '8d'], \
'debmdk-all-nbi': ['3d', '4d', '8d'], \
'dtlz8': ['3d', '4d', '6d', '8d'], \
'dtlz8-nbi': ['3d', '4d', '6d', '8d'], \
'c2dtlz2': ['3d', '4d', '5d', '8d'], \
'c2dtlz2-nbi': ['3d', '4d', '5d', '8d'], \
'cdebmdk': ['3d', '4d', '8d'], \
'cdebmdk-nbi': ['3d', '4d', '8d'], \
'c0dtlz2': ['3d', '4d', '8d'], \
'c0dtlz2-nbi': ['3d', '4d', '8d'], \
'crash-nbi': ['3d'], 'crash-c1-nbi': ['3d'], 'crash-c2-nbi': ['3d'], \
'gaa': ['10d'], \
'gaa-nbi': ['10d']}
for pf in list(pfs.keys()):
for dim in pfs[pf]:
fullpathf = "../data/{0:s}/{1:s}/dataf.csv".format(pf, dim)
if os.path.exists(fullpathf):
path, filenamef = os.path.split(fullpathf)
dirs = path.split('/')
frontname = dirs[-2]
# load the front
F = np.loadtxt(fullpathf, delimiter=',')
print(fullpathf, F.shape, dirs, frontname)
CV, Mu, Ik = load_props(path)
S,C = decide_size_color(CV, Mu, Ik)
figpath = os.path.join(path, "scatter3d.pdf")
with plt.rc_context({"text.usetex": True, "font.size": 12}):
scatter.plot(F, ax=Axes3D(plt.figure()), s=S, c=C, euler=camera_angles[pf][dim], \
xbound = (-1.0,1.0), ybound = (-1.0,1.0), zbound=(-1.0,1.0))
# save the fig
plt.savefig(figpath, bbox_inches='tight', pad_inches=0, dpi=150)
plt.show()